﻿Imports System.Windows.Forms
Imports System.Web
Imports System.Net
Imports System.Text
Imports System.Configuration
Imports System.IO
Imports Newtonsoft.Json
Imports System.IO.Compression

Public Class MyFriend
    Public id As String = ""
    Public name As String = ""
    Public Url As String = ""
    Public username As String = ""
End Class

Public Class CSDNLOGIN

    Private Shared _Cookie As String = ""
    Private Shared _CookieContiner As New CookieContainer
    Private Shared _bLogin As Boolean = False
    Public Shared _WebProxy As WebProxy
    Public Shared Function 是否登录() As Boolean
        Return _bLogin
    End Function

    Public Enum 登陆错误
        用户名或密码不能为空
        用户名或密码错误
    End Enum

    ''' <summary>
    ''' 登陆函数
    ''' </summary>
    ''' <param name="strUsername">用户名</param>
    ''' <param name="strPwd">密码</param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Shared Function Login(ByVal strUsername As String, ByVal strPwd As String) As Boolean
        Try
            Dim strLoginUrl As String = " "
            Dim sb As New StringBuilder
            sb.Append("http://passport.csdn.net/ajax/accounthandler.ashx?t=log&u=")
            sb.Append(strUsername)
            sb.Append("&p=")
            sb.Append(strPwd)
            sb.Append("&c=&remember=0&f=http://passport.csdn.net/account/login  HTTP/1.1")
            strLoginUrl = sb.ToString
            Dim wbr As HttpWebRequest = CType(WebRequest.Create(strLoginUrl), HttpWebRequest)
            If _WebProxy IsNot Nothing Then
                wbr.Proxy = _WebProxy
            End If
            wbr.Accept = "*/*"
            wbr.Headers.Add("x-requested-with", "XMLHttpRequest")
            wbr.Headers.Add("Accept-Language: zh-cn")
            wbr.Referer = "http://passport.csdn.net/account/loginbox?callback=logined"
            wbr.ContentType = "application/x-www-form-urlencoded"
            wbr.Headers.Add("Accept-Encoding", "gzip, deflate")
            wbr.CookieContainer = _CookieContiner
            wbr.UserAgent = "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; POTU(RR:28031409:0:); Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1) ; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E)"
            Dim wbres As HttpWebResponse = wbr.GetResponse()

            'Dim sr As StreamReader = New StreamReader(wbres.GetResponseStream(), True)
            'Dim strContent As String = sr.ReadToEnd
            'wbres.Close()
            'sr.Close()

            Dim strContent As String = UTIL.ReadStreamEncodingContent(wbres)

            '{"status":true,"error":"","data":""}
            Dim strStatus As String = ""
            Dim strError As String = ""
            Dim strData As String = ""

            Dim tr As New IO.StringReader(strContent)
            Dim jtr As JsonTextReader = New JsonTextReader(tr)
            While jtr.Read
                If jtr.TokenType = JsonToken.PropertyName AndAlso jtr.Value = "status" Then
                    If jtr.Read = True Then
                        strStatus = jtr.Value
                    End If
                End If

                If jtr.TokenType = JsonToken.PropertyName AndAlso jtr.Value = "error" Then
                    If jtr.Read = True Then
                        strError = jtr.Value
                    End If
                End If

                If jtr.TokenType = JsonToken.PropertyName AndAlso jtr.Value = "data" Then
                    If jtr.Read = True Then
                        strData = jtr.Value
                    End If
                End If
            End While

            If strStatus.ToLower = "true" Then
                _bLogin = True
                Return True
            End If

            _bLogin = False
            Return False

        Catch ex As Exception
            _bLogin = False
            Return False
        End Try

    End Function

    ''' <summary>
    ''' 登陆空间 http://hi.csdn.net/space.php?do=home
    ''' </summary>
    ''' <param name="strBolgUrl">博客网址</param>
    ''' <param name="lstFriend">返回该朋友的朋友</param>
    ''' <param name="lstComment">返回该朋友的关注的人</param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Shared Function 登陆空间(ByVal strBolgUrl As String, ByRef lstFriend As List(Of MyFriend), ByRef lstComment As List(Of MyFriend)) As Boolean

        Try
            Dim strLoginUrl As String = strBolgUrl
            Dim wbr As HttpWebRequest = CType(WebRequest.Create(strLoginUrl), HttpWebRequest)
            If _WebProxy IsNot Nothing Then
                wbr.Proxy = _WebProxy
            End If
            wbr.AllowAutoRedirect = True
            wbr.CookieContainer = _CookieContiner
            Dim wbres As HttpWebResponse = wbr.GetResponse()

            Dim sr As StreamReader = New StreamReader(wbres.GetResponseStream(), True)
            Dim strContent As String = sr.ReadToEnd
            wbres.Close()
            sr.Close()

            lstFriend = UTIL.ParseBlogContentUrl(strContent)

            Return True
        Catch ex As Exception
            Return False
        End Try

        Return False

    End Function

    ''' <summary>
    ''' 登陆空间 http://hi.csdn.net/space.php?do=home
    ''' </summary>
    Public Shared Function 登陆空间(ByVal strBolgUrl As String, ByVal name As String, ByRef username As String, ByRef blogUrl As String) As Boolean

        Try
            Dim strLoginUrl As String = strBolgUrl
            Dim wbr As HttpWebRequest = CType(WebRequest.Create(strLoginUrl), HttpWebRequest)
            If _WebProxy IsNot Nothing Then
                wbr.Proxy = _WebProxy
            End If
            wbr.AllowAutoRedirect = True
            wbr.CookieContainer = _CookieContiner
            Dim wbres As HttpWebResponse = wbr.GetResponse()

            Dim sr As StreamReader = New StreamReader(wbres.GetResponseStream(), True)
            Dim strContent As String = sr.ReadToEnd
            wbres.Close()
            sr.Close()

            If UTIL.ParseUsername(strContent, username) = False Then
                username = name
            End If

            blogUrl = "http://blog.csdn.net/" & username

            Return True

        Catch ex As Exception
            Return False
        End Try

        Return False

    End Function

    Public Shared Function 分析请求好友(ByRef lst请求好友 As List(Of 请求好友)) As Boolean
        Dim strUrl As String = "http://hi.csdn.net/cp.php?ac=friend&op=request"

        Try
            Dim strLoginUrl As String = strUrl
            Dim wbr As HttpWebRequest = CType(WebRequest.Create(strLoginUrl), HttpWebRequest)
            If _WebProxy IsNot Nothing Then
                wbr.Proxy = _WebProxy
            End If
            wbr.AllowAutoRedirect = True
            wbr.CookieContainer = _CookieContiner
            Dim wbres As HttpWebResponse = wbr.GetResponse()

            Dim sr As StreamReader = New StreamReader(wbres.GetResponseStream(), True)
            Dim strContent As String = sr.ReadToEnd
            wbres.Close()
            sr.Close()

            Return UTIL.分析要请求的好友(strContent, lst请求好友)

        Catch ex As Exception
            Return False
        End Try

        Return False

    End Function

    Public Shared Function 留言(ByVal uid As String, ByVal strSpace As String, ByRef strRs As String) As Boolean

        Try
            Dim strLoginUrl As String = strSpace
            Dim wbr As HttpWebRequest = CType(WebRequest.Create(strLoginUrl), HttpWebRequest)
            If _WebProxy IsNot Nothing Then
                wbr.Proxy = _WebProxy
            End If
            wbr.AllowAutoRedirect = True
            wbr.CookieContainer = _CookieContiner
            Dim wbres As HttpWebResponse = wbr.GetResponse()

            Dim sr As StreamReader = New StreamReader(wbres.GetResponseStream(), True)
            Dim strContent As String = sr.ReadToEnd
            wbres.Close()
            sr.Close()

            strLoginUrl = "http://hi.csdn.net/cp.php?ac=comment&inajax=1"
            wbr = CType(WebRequest.Create(strLoginUrl), HttpWebRequest)
            If _WebProxy IsNot Nothing Then
                wbr.Proxy = _WebProxy
            End If
            wbr.AllowAutoRedirect = True
            wbr.Referer = strSpace

            wbr.Method = "POST"
            wbr.Accept = "image/jpeg, application/x-ms-application, image/gif, application/xaml+xml, image/pjpeg, application/x-ms-xbap, application/x-shockwave-flash, */*"
            wbr.ContentType = "application/x-www-form-urlencoded"
            wbr.Referer = strSpace
            wbr.Headers.Add("Accept-Language: zh-cn")
            wbr.Headers.Add("Accept-Encoding: gzip, deflate")
            wbr.UserAgent = "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; POTU(RR:28031409:0:); Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1) ; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E)"
            Dim postBytes() As Byte = GetPostData留言(strContent, uid)
            Dim postLength As Integer = postBytes.Length
            wbr.ContentLength = postLength
            wbr.CookieContainer = _CookieContiner

            Dim rs As Stream = wbr.GetRequestStream()
            rs.Write(postBytes, 0, postLength)
            rs.Close()

            wbres = wbr.GetResponse()
            sr = New StreamReader(wbres.GetResponseStream(), True)
            strContent = sr.ReadToEnd
            wbres.Close()
            sr.Close()

            UTIL.Get发送完留言返回内容(strContent, strRs)

            Return True

        Catch ex As Exception
            Return False
        End Try

        Return False
    End Function

    Public Shared Function 自动添加请求的好友(ByVal uid As String, ByVal id As String, ByRef strRs As String) As Boolean
        Try
            Dim strLoginUrl As String = "http://hi.csdn.net/cp.php?ac=friend&op=add&uid=" & uid & "&ajaxmenuid=" & id & "_menu&popupmenu_box=1&inajax=1"
            Dim wbr As HttpWebRequest = CType(WebRequest.Create(strLoginUrl), HttpWebRequest)
            If _WebProxy IsNot Nothing Then
                wbr.Proxy = _WebProxy
            End If
            wbr.AllowAutoRedirect = True
            wbr.Referer = "http://hi.csdn.net/cp.php?ac=friend&op=request"
            wbr.Headers.Add("Accept-Language: zh-cn")
            wbr.Headers.Add("Accept-Encoding: gzip, deflate")
            wbr.UserAgent = "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; POTU(RR:28031409:0:); Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1) ; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E)"

            wbr.CookieContainer = _CookieContiner
            Dim wbres As HttpWebResponse = wbr.GetResponse()

            'Dim responseStream As DeflateStream = New DeflateStream(wbres.GetResponseStream(), CompressionMode.Decompress)
            Dim html As String
            If wbres.ContentEncoding.ToLower.Contains("gzip") Then
                Dim responseStream As GZipStream = New GZipStream(wbres.GetResponseStream(), CompressionMode.Decompress)
                Dim streamReader As StreamReader = New StreamReader(responseStream)
                html = streamReader.ReadToEnd()
                responseStream.Close()
                streamReader.Close()
            ElseIf wbres.ContentEncoding.ToLower.Contains("deflate") Then
                Dim responseStream As DeflateStream = New DeflateStream(wbres.GetResponseStream(), CompressionMode.Decompress)
                Dim streamReader As StreamReader = New StreamReader(responseStream)
                html = streamReader.ReadToEnd()
                responseStream.Close()
                streamReader.Close()
            Else
                Dim streamReader As StreamReader = New StreamReader(wbres.GetResponseStream())
                html = streamReader.ReadToEnd()
                streamReader.Close()
            End If

            '分析数据
            Dim formhash As String = ""

            If UTIL.GetFormHash(html, formhash) = True Then
                strLoginUrl = "http://hi.csdn.net/cp.php?ac=friend&op=add&uid=" & uid & "&inajax=1"
                wbr = CType(WebRequest.Create(strLoginUrl), HttpWebRequest)
                If _WebProxy IsNot Nothing Then
                    wbr.Proxy = _WebProxy
                End If
                wbr.AllowAutoRedirect = True
                wbr.Method = "POST"
                wbr.Accept = "image/jpeg, application/x-ms-application, image/gif, application/xaml+xml, image/pjpeg, application/x-ms-xbap, application/x-shockwave-flash, */*"
                wbr.ContentType = "application/x-www-form-urlencoded"
                wbr.Referer = "http://hi.csdn.net/cp.php?ac=friend&op=request"
                wbr.Headers.Add("Accept-Language: zh-cn")
                wbr.Headers.Add("Accept-Encoding: gzip, deflate")
                wbr.UserAgent = "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; POTU(RR:28031409:0:); Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1) ; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E)"
                Dim postBytes() As Byte = GetPostData自动添加请求好友(formhash, uid)
                Dim postLength As Integer = postBytes.Length
                wbr.ContentLength = postLength
                wbr.CookieContainer = _CookieContiner

                Dim rs As Stream = wbr.GetRequestStream()
                rs.Write(postBytes, 0, postLength)
                rs.Close()

                wbres = wbr.GetResponse()

                Dim sr As StreamReader = New StreamReader(wbres.GetResponseStream(), True)
                Dim strContent As String = sr.ReadToEnd
                wbres.Close()
                sr.Close()

                UTIL.Get发送完关注返回内容(strContent, strRs)
            End If

            Return True

        Catch ex As Exception
            Return False
        End Try

        Return False
    End Function

    Public Shared Function 打招呼(ByVal uid As String, ByVal strSpace As String, ByRef strRs As String) As Boolean

        Try
            Dim strLoginUrl As String = "http://hi.csdn.net/cp.php?ac=poke&op=send&uid=" & uid & "&ajaxmenuid=a_poke_menu&popupmenu_box=1&inajax=1"
            Dim wbr As HttpWebRequest = CType(WebRequest.Create(strLoginUrl), HttpWebRequest)
            If _WebProxy IsNot Nothing Then
                wbr.Proxy = _WebProxy
            End If
            wbr.AllowAutoRedirect = True
            wbr.Referer = strSpace
            wbr.Headers.Add("Accept-Language: zh-cn")
            wbr.Headers.Add("Accept-Encoding: gzip, deflate")
            wbr.UserAgent = "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; POTU(RR:28031409:0:); Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1) ; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E)"

            wbr.CookieContainer = _CookieContiner
            Dim wbres As HttpWebResponse = wbr.GetResponse()

            'Dim responseStream As DeflateStream = New DeflateStream(wbres.GetResponseStream(), CompressionMode.Decompress)
            Dim html As String
            If wbres.ContentEncoding.ToLower.Contains("gzip") Then
                Dim responseStream As GZipStream = New GZipStream(wbres.GetResponseStream(), CompressionMode.Decompress)
                Dim streamReader As StreamReader = New StreamReader(responseStream)
                html = streamReader.ReadToEnd()
                responseStream.Close()
                streamReader.Close()
            ElseIf wbres.ContentEncoding.ToLower.Contains("deflate") Then
                Dim responseStream As DeflateStream = New DeflateStream(wbres.GetResponseStream(), CompressionMode.Decompress)
                Dim streamReader As StreamReader = New StreamReader(responseStream)
                html = streamReader.ReadToEnd()
                responseStream.Close()
                streamReader.Close()
            Else
                Dim streamReader As StreamReader = New StreamReader(wbres.GetResponseStream())
                html = streamReader.ReadToEnd()
                streamReader.Close()
            End If

            '分析数据
            Dim formhash As String = ""

            If UTIL.GetFormHash(html, formhash) = True Then
                strLoginUrl = "http://hi.csdn.net/cp.php?ac=poke&op=send&uid=" & uid & "&inajax=1"
                wbr = CType(WebRequest.Create(strLoginUrl), HttpWebRequest)
                If _WebProxy IsNot Nothing Then
                    wbr.Proxy = _WebProxy
                End If
                wbr.AllowAutoRedirect = True
                wbr.Referer = strSpace

                wbr.Method = "POST"
                wbr.Accept = "image/jpeg, application/x-ms-application, image/gif, application/xaml+xml, image/pjpeg, application/x-ms-xbap, application/x-shockwave-flash, */*"
                wbr.ContentType = "application/x-www-form-urlencoded"
                wbr.Referer = strSpace
                wbr.Headers.Add("Accept-Language: zh-cn")
                wbr.Headers.Add("Accept-Encoding: gzip, deflate")
                wbr.UserAgent = "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; POTU(RR:28031409:0:); Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1) ; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E)"
                Dim postBytes() As Byte = GetPostData打招呼(formhash, uid, strSpace)
                Dim postLength As Integer = postBytes.Length
                wbr.ContentLength = postLength
                wbr.CookieContainer = _CookieContiner

                Dim rs As Stream = wbr.GetRequestStream()
                rs.Write(postBytes, 0, postLength)
                rs.Close()

                wbres = wbr.GetResponse()

                Dim sr As StreamReader = New StreamReader(wbres.GetResponseStream(), True)
                Dim strContent As String = sr.ReadToEnd
                wbres.Close()
                sr.Close()

                UTIL.Get发送完关注返回内容(strContent, strRs)
            End If

            Return True

        Catch ex As Exception
            Return False
        End Try

        Return False

    End Function

    Public Shared Function 添加好友(ByVal uid As String, ByVal strSpace As String, ByRef strRs As String) As Boolean

        Try
            Dim strLoginUrl As String = "http://hi.csdn.net/cp.php?ac=friend&op=add&uid=" & uid & "&ajaxmenuid=a_friend_menu&popupmenu_box=1&inajax=1"
            Dim wbr As HttpWebRequest = CType(WebRequest.Create(strLoginUrl), HttpWebRequest)
            If _WebProxy IsNot Nothing Then
                wbr.Proxy = _WebProxy
            End If
            wbr.AllowAutoRedirect = True
            wbr.Referer = strSpace
            wbr.Headers.Add("Accept-Language: zh-cn")
            wbr.Headers.Add("Accept-Encoding: gzip, deflate")
            wbr.UserAgent = "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; POTU(RR:28031409:0:); Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1) ; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E)"

            wbr.CookieContainer = _CookieContiner
            Dim wbres As HttpWebResponse = wbr.GetResponse()

            Dim html As String
            Dim compressStream As Stream = Nothing
            Dim streamReader As StreamReader
            If wbres.ContentEncoding.ToLower.Contains("gzip") Then
                compressStream = New GZipStream(wbres.GetResponseStream(), CompressionMode.Decompress)
                streamReader = New StreamReader(compressStream)
                html = streamReader.ReadToEnd()
                compressStream.Close()
                streamReader.Close()
            ElseIf wbres.ContentEncoding.ToLower.Contains("deflate") Then
                compressStream = New DeflateStream(wbres.GetResponseStream(), CompressionMode.Decompress)
                streamReader = New StreamReader(compressStream)
                html = streamReader.ReadToEnd()
                compressStream.Close()
                streamReader.Close()
            Else
                streamReader = New StreamReader(wbres.GetResponseStream())
                html = streamReader.ReadToEnd()
                streamReader.Close()
            End If

            '分析数据
            Dim formhash As String = ""

            If UTIL.GetFormHash(html, formhash) = True Then
                strLoginUrl = "http://hi.csdn.net/cp.php?ac=friend&op=add&uid=" & uid & "&inajax=1"
                wbr = CType(WebRequest.Create(strLoginUrl), HttpWebRequest)
                If _WebProxy IsNot Nothing Then
                    wbr.Proxy = _WebProxy
                End If
                wbr.AllowAutoRedirect = True
                wbr.Referer = strSpace

                wbr.Method = "POST"
                wbr.Accept = "image/jpeg, application/x-ms-application, image/gif, application/xaml+xml, image/pjpeg, application/x-ms-xbap, application/x-shockwave-flash, */*"
                wbr.ContentType = "application/x-www-form-urlencoded"
                wbr.Referer = strSpace
                wbr.Headers.Add("Accept-Language: zh-cn")
                wbr.Headers.Add("Accept-Encoding: gzip, deflate")
                wbr.UserAgent = "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; POTU(RR:28031409:0:); Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1) ; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E)"
                Dim postBytes() As Byte = GetPostData添加好友(formhash, uid, strSpace)
                Dim postLength As Integer = postBytes.Length
                wbr.ContentLength = postLength
                wbr.CookieContainer = _CookieContiner

                Dim rs As Stream = wbr.GetRequestStream()
                rs.Write(postBytes, 0, postLength)
                rs.Close()

                wbres = wbr.GetResponse()

                Dim sr As StreamReader = New StreamReader(wbres.GetResponseStream(), True)
                Dim strContent As String = sr.ReadToEnd
                wbres.Close()
                sr.Close()

                UTIL.Get发送完留言返回内容(strContent, strRs)
            Else
                UTIL.Get发送完留言返回内容(html, strRs)
            End If

            Return True

        Catch ex As Exception
            Return False
        End Try

        Return False

    End Function

    Public Shared Function GetPostData添加好友(ByVal formhash As String, ByVal uid As String, ByVal strSpace As String) As Byte()
        'iconid
        '0其他
        '1通过本站认识
        '2通过活动认识
        '3通过朋友认识
        '4亲人
        '5同事
        '6同学
        '7不认识
        If _lstFriend.Count = 0 Then
            _lstFriend.AddRange(New String() {0, 1, 2, 3, 4, 6, 7})
        End If
        Dim rn As New Random
        Dim iconid As Integer = rn.Next(0, 6)
        iconid = _lstFriend(iconid)
        Dim postData As String = "note=&gid=" & iconid & "&refer=" & strSpace & "&addsubmit=true&formhash=" & formhash
        Dim postBytes() As Byte = Encoding.Default.GetBytes(postData)

        Return postBytes

    End Function

    Public Shared Function GetPostData自动添加请求好友(ByVal formhash As String, ByVal uid As String) As Byte()
        'iconid
        '1 通过本站认识
        Dim postData As String = "gid=1&refer=http://hi.csdn.net/cp.php?ac=friend&op=request&add2submit=true" & "&formhash=" & formhash
        Dim postBytes() As Byte = Encoding.Default.GetBytes(postData)

        Return postBytes

    End Function

    Public Shared Function GetPostData打招呼(ByVal formhash As String, ByVal uid As String, ByVal strSpace As String) As Byte()
        'iconid
        '0 不用动作
        '1 踩一下2 握个手3 微笑
        '4 加油 6拥抱 12拍拍肩膀
        If _lsticonid.Count = 0 Then
            _lsticonid.AddRange(New String() {0, 1, 2, 3, 4, 6, 12})
        End If
        Dim rn As New Random
        Dim iconid As Integer = rn.Next(0, 6)
        iconid = _lsticonid(iconid)
        Dim postData As String = "iconid=" & iconid & "&note=&refer=" & strSpace & "&pokesubmit=true&formhash=" & formhash
        Dim postBytes() As Byte = Encoding.Default.GetBytes(postData)

        Return postBytes

    End Function

    Public Shared Function GetPostData留言(ByVal spaceContent As String, ByVal uid As String) As Byte()
        If _lstComment.Count = 0 Then
            _lstComment.AddRange(CSDNBL.GetAllComment())
        End If
        Dim rn As New Random
        Dim message As Integer = rn.Next(0, _lstComment.Count - 1)
        Dim strMessage As String
        strMessage = _lstComment(message)

        Dim fromHash As String = ""
        UTIL.GetFormHash(spaceContent, fromHash)

        Dim postData As String = "message=" & HttpUtility.UrlEncode(strMessage) & "&refer=" & HttpUtility.UrlEncode("space.php?uid=" & uid) & "&id=" & uid & "&idtype=uid&commentsubmit=true&formhash=" & fromHash

        'Dim returnValue As String = HttpUtility.UrlEncode(postData)
        Dim postBytes() As Byte = Encoding.Default.GetBytes(postData)

        Return postBytes

    End Function

    Public Shared Function 添加好友(ByVal uid As String) As Boolean
        Return True
    End Function

    Private Shared _lsticonid As New List(Of String)
    Private Shared _lstComment As New List(Of String)
    Private Shared _lstFriend As New List(Of String)

    ''' <summary>
    ''' 进行关注 
    ''' </summary>
    Public Shared Function 关注(ByVal uid As String, ByRef str As String) As Boolean

        Try
            Dim strLoginUrl As String = "http://hi.csdn.net/cp.php?ac=follow&op=add&uid=" & uid & "&ajaxmenuid=a_follow_menu&popupmenu_box=1&inajax=1"
            Dim wbr As HttpWebRequest = CType(WebRequest.Create(strLoginUrl), HttpWebRequest)
            If _WebProxy IsNot Nothing Then
                wbr.Proxy = _WebProxy
            End If
            wbr.Referer = "http://hi.csdn.net/space-" & uid & ".html"
            wbr.AllowAutoRedirect = True
            wbr.CookieContainer = _CookieContiner
            Dim wbres As HttpWebResponse = wbr.GetResponse()

            'Dim sr As StreamReader = New StreamReader(wbres.GetResponseStream(), True)
            'Dim strContent As String = sr.ReadToEnd
            'sr.Close()

            Dim strContent As String = UTIL.ReadStreamEncodingContent(wbres)
            Return UTIL.Get添加关注返回内容(strContent, str)

        Catch ex As Exception
            Return False
        End Try

        Return False

    End Function
End Class
